//package org.jupiter.blog.authentic.handler;
//
//import jakarta.servlet.FilterChain;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.stereotype.Component;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import java.io.IOException;
//import java.util.Collections;
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class JupiterTokenFilter extends OncePerRequestFilter {
//
//	@Autowired
//	private StringRedisTemplate redisTemplate;
//
//	@Override
//	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
//			FilterChain filterChain) throws ServletException, IOException {
//
//		String token = request.getHeader("Authorization");
//		if (token != null && token.startsWith("Bearer ")){
//			token = token.substring(7); // 去掉 "Bearer "
//
//			String key = "jupiter:auth:token:" + token;
//			String username = redisTemplate.opsForValue().get(key);
//
//			if (username != null){
//				// 刷新 token 过期时间（滑动过期）
//				redisTemplate.expire(key, 30, TimeUnit.MINUTES);
//
//				// 设置认证信息，注入 Spring Security 上下文
//				UsernamePasswordAuthenticationToken auth =
//						new UsernamePasswordAuthenticationToken(username, null, Collections.emptyList());
//				SecurityContextHolder.getContext().setAuthentication(auth);
//			}
//		}
//
//		filterChain.doFilter(request, response);
//	}
//}
